home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / portdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  2.5 KB  |  69 lines

  1. {
  2. GPC demo program for port access from GPC on x86 platforms
  3. (tested under Linux/x86 and DJGPP). Must be run as root or
  4. suid root under Unix systems!
  5.  
  6. DISCLAIMER: This program might interfere with your hardware, or
  7. even do damage to it! The author disclaims any liability for the
  8. consequences of running the program or not being able to run it.
  9. Use it at your own risk!
  10.  
  11. Copyright (C) 1998-2001 Free Software Foundation, Inc.
  12.  
  13. Author: Frank Heckenbach <frank@pascal.gnu.de>
  14.  
  15. This program is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU General Public License as
  17. published by the Free Software Foundation, version 2.
  18.  
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23.  
  24. You should have received a copy of the GNU General Public License
  25. along with this program; see the file COPYING. If not, write to
  26. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  27. Boston, MA 02111-1307, USA.
  28.  
  29. As a special exception, if you incorporate even large parts of the
  30. code of this demo program into another program with substantially
  31. different functionality, this does not cause the other program to
  32. be covered by the GNU General Public License. This exception does
  33. not however invalidate any other reasons why it might be covered
  34. by the GNU General Public License.
  35. }
  36.  
  37. program PortDemo;
  38.  
  39. uses GPC, Ports;
  40.  
  41. const
  42.   BasePort = $278;
  43.  
  44. begin
  45.   { Allow acces to ports BasePort .. BasePort + 2 }
  46.   if IOPerm (BasePort, 3, 1) <> 0 then
  47.     begin
  48.       Writeln (StdErr, 'Could not set I/O permissions. Please run as root.');
  49.       Halt (1)
  50.     end;
  51.  
  52.   { Give up root privileges as soon as possible }
  53.   if SetEUID (UserID (False)) <> 0 then
  54.     begin
  55.       Writeln (StdErr, 'Could not reset effective user ID. Should not happen...');
  56.       Halt (1)
  57.     end;
  58.  
  59.   { Play around with the ports... }
  60.   Writeln ('Value at port ', BasePort, ' is ', InPortB (BasePort));
  61.   Writeln ('Value at ports ', BasePort, '/', BasePort + 1, ' is ', InPortW (BasePort));
  62.   Writeln ('Setting port ',BasePort, ' to 42...');
  63.   OutPortB (BasePort, 42);
  64.   Writeln ('Value at ports ', BasePort, '/', BasePort + 1, ' is now ', InPortW (BasePort));
  65.   Writeln ('Setting port ',BasePort, ' to 0 through OutPortW...');
  66.   OutPortW (BasePort, 256 * InportB (BasePort + 1));
  67.   Writeln ('Value at ports ', BasePort, '/', BasePort + 1, ' is now ', InPortW (BasePort));
  68. end.
  69.